Instance Interfaces and Mix-ins for Dynamic Languages

ABSTRACT

Various technologies and techniques are disclosed for using contracts in dynamic languages. For example, a contract can be directly associated with an object. The contract can then be used to provide type safety for the object. As another example, contracts can be used with mix-ins. A declaration for a contract is provided with a mix-in. The contract is associated with a target object at runtime when applying the mix-in. Conditions can be assigned to mix-ins that must be met before the mix-in can be applied to the target object. At runtime, if the target object meets the one or more conditions, then the mix-in can be applied to the target object.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application claims priority to and is a continuation of co-pendingU.S. patent application Ser. No. 15/145,064 entitled “InstancesInterfaces and Mix-ins for Dynamic Languages” and filed on May 3, 2016which is a continuation of U.S. patent application Ser. No. 11/888,577entitled “Instance Interfaces and Mix-ins for Dynamic Languages” andfiled Aug. 1, 2007, which are incorporated herein by reference.

BACKGROUND

Software developers create software using one or more programminglanguages. Programming languages are usually either statically typedlanguages, or they are dynamic languages. Statically typed languages aregenerally languages that provide a fixed code structure and/or statictyping. With a fixed code structure, classes and other structures areimmutable at runtime, meaning that their structure cannot be modifiedafter the class or structure is created. With static typing, variablesand parameters must be assigned at design time so that they can be knownat compile time. Statically typed languages can include some or all ofthese characteristics. Some examples of statically typed languagesinclude C#, Java, C, and C++.

Dynamic languages are generally languages that provide dynamic variabletyping and/or runtime code modification. With dynamic variable typing,variables do not have to be declared before use, and their type(integer, string, etc.) is thus not determined until runtime. Languagesthat implement dynamic typing are often referred to as dynamically typedlanguages (in addition to the term dynamic languages). With runtime codemodification, classes and other details about the structure of thesource code can be modified dynamically. For example, methods may beadded to classes or structures at runtime. Some examples of dynamiclanguages include JavaScript, Ruby, Python, and PHP. These languages areoften referred to as “scripting” languages because of the fact thattheir source code is contained in one or more textual script files. Theterm “dynamic language script” as used herein is meant to include one ormore files that contain source code written in a dynamic language.

These features typically provided by dynamic languages offer softwaredevelopers with a lot of flexibility. As an example, dynamic languagescan be used to build objects from scratch or extend existing objects atruntime. The term “object” as used herein is referring to objects in theobject oriented world of programming, and is meant to include anindividual unit of runtime data storage that is used as the basicbuilding block of a program. Objects can optionally have methods(functions, procedures, etc.) associated with them that can be runwithin the context of the unit of runtime data storage. While dynamiclanguages offer flexibility, with this flexibility comes some problems.For example, a well defined type is a lot more difficult to determinesince the specific type that a variable will be used for does not haveto be declared in advance. Thus, the program does not know whether avariable called counter is an integer, a string, a double, or somethingelse. This can make parameter validation and other validationsproblematic, because any verification has to make assumptions about whata parameter object can or cannot do.

The feature known as “type safety”, usually associated with staticallytyped languages, seems to conflict with the spirit of dynamic languages.The term type safety generally refers to determining what type an objector variable represents, and ensuring that the object or variable is onlyused in a manner consistent with the type expected. For example, if aline of code attempts to assign a variable that stores an integer valueto a variable that stores a string value, the compiler could raise acompiler error based upon a type mismatch. That is because the integervariable is not capable of storing the value represented in the stringvariable.

As noted earlier, in dynamically typed languages, such type safety isnot present. This problem is usually solved using a technique known as“duck-typing”, which uses the reflection capabilities that dynamiclanguages typically possess to inspect the object and check for aparticular member's existence before using it. This is often called“duck-typing” based on the saying “if it quacks like a duck, you canconsider it to be a duck”. While the duck-typing technique can work wellin common scenarios, it presents a number of challenges.

One problem with duck typing is that there is not a one to one mappingbetween a member (variable, object, etc.) name and the semantics of thatmember. The context is usually necessary to get this one to one mapping.This context, in statically typed languages, is the type. For example,if an object has a start method, it could have been written to start ananimation, which would be clear if it is known that the object is ananimation. Alternatively, the object could have been written to start atimer, which is clear if it is known that the object is a timer. Thisworks well if the context can be easily inferred, such as if the codethat creates the object is the same code that uses it. But this scenariofails when the context is not available. For example, suppose theprogram is inspecting an unknown object graph and wants to start allanimations in it. By relying on the presence of a start method only,then all timers would be started, which is not the intent. Using thehypothetical example with statically typed languages, you can just checkfor the type of an object, and if it derives from Animation, you cancall the start method on the Animation object with reasonable confidencethat what you intend is what will happen.

Another problem with duck-typing is that it hides important detailswithin the code. For example, in dynamic languages, you typically haveto look at the implementation (the underlying source code of theparticular object or method) to figure out what constraints are going tobe imposed on parameters. This problem is usually solved by putting theburden on documentation. However, this part of documentation is usuallyautomatically generated from method signatures in statically typedlanguages. This is because in statically typed languages, the signatureof a method generally identifies everything needed in order to call it.Thus, dynamic languages are losing at least part of the boost ofproductivity provided by dynamic typing by requiring manual authoring ofdocumentation that could be generated.

In statically typed languages, these problems do not typically existbecause objects are instances of one or several types and implement oneor more contracts, usually in the way of interfaces. The term “contract”means a specified agreement that any object or other programmingstructure that is providing an implementation for a given functionalityagrees to implement. Interfaces are the most common way for providing adefinition for a contract. Interfaces require that any object (or othermember) that wishes to implement the interface provide a specificimplementation for all of the members that are defined in the interface.Some non-limiting examples of members include properties, methods,events, and/or fields. The interface itself does not contain anyimplementation of the functionality, but rather just the definition ofwhat the implementation should contain. There are also other ways tospecify a contract, such as by specifying an abstract base class thatother classes can inherit from, or by using other techniques forspecifying what features certain objects or other members mustimplement.

Contracts and interfaces are very useful, but as a practical matter,they usually do not exist at all in dynamic languages. Interfaces (orother contracts) make a lot less sense when objects can be built fromscratch, such as with dynamic languages. The root of that problem isthat interfaces are implemented by types. As previously discussed,statically typed languages typically provide type safe members withtypes that are known at compile time, whereas dynamic languages do not.Thus, with statically typed languages, the interface is associated witha type, and the type is then associated with the underlying object.Thus, the relationship between the interface and the object it isassociated with is an indirect relationship that is established throughthe type itself. The lack of type safety is one reason why interfacesare not typically used in dynamic languages as they are in staticallytyped languages.

On a separate but related note, some dynamic languages use a generic wayof adding a specific set of features to an object dynamically, but underthe form of a module or mix-in. More specifically, a mix-in is one ormore member implementations that can be added dynamically to an object(the target). The term “target object” will be used herein to refer toan object to which a mix-in is to be applied. Mix-ins are a conceptsimilar to multiple inheritance, but for dynamic languages. A mix-in cancontain methods that can be added in one operation to an object, such aswith an equivalent to an include statement that refers to the mix-ingroup of code. From the user code's perspective, it is still necessaryin principle to test for the existence of each method before using it.There is also a small possibility that an object may appear to providecertain functionality but be something entirely different. Furthermore,members defined in the mix-in may conflict with and overwrite existingmembers of the object.

SUMMARY

Various technologies and techniques are disclosed for using contracts indynamic languages. In one implementation, a contract or interface can bedirectly associated with an object. The contract or interface can thenbe used to provide type safety for the object. As a non-limitingexample, the contract can be used to ensure that one or more parameterspassed to a particular method in the object are of the data typesexpected by the method.

In another implementation, contracts can be used with mix-ins. Adeclaration for an implemented contract is provided with a mix-in. Theimplemented contract is associated with a target object at runtime whenapplying the mix-in to the target object. The target object may be usedin a later context that requires the contract. The code in the latercontext is able to verify the implemented contract on the target objectusing reflection.

In yet another implementation, conditions can be assigned to mix-insthat must be met before the mix-in can be applied to the target object.The condition can be a constraint contract that was assigned to themix-in, and/or can be other conditions. At runtime, if the target objectmeets the one or more conditions, then the mix-in can be applied to thetarget object. Otherwise, an exception or other suitable action can betaken.

This Summary was provided to introduce a selection of concepts in asimplified form that are further described below in the DetailedDescription. This Summary is not intended to identify key features oressential features of the claimed subject matter, nor is it intended tobe used as an aid in determining the scope of the claimed subjectmatter.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is a diagrammatic view of a system of one implementation fordirectly associating contracts with objects.

FIG. 2 is a diagrammatic view of a dynamic language scriptingapplication of one implementation.

FIG. 3 is a process flow diagram for one implementation illustrating thestages involved in allowing a user to directly associate contract(s)with object(s) in a dynamic language.

FIG. 4 is a diagrammatic view for one implementation illustrating inexemplary API's for declaring and/or using contracts directly with anobject.

FIG. 5 is a process flow diagram for one implementation illustrating thestages involved in associating mix-ins with contracts.

FIG. 6 is a process flow diagram for one implementation illustrating thestages involved in restricting use of mix-ins based on contracts orother conditions.

FIG. 7 is a diagrammatic view for one implementation illustratingexemplary API's for registering and/or using mix-ins with an object.

FIG. 8 is a process flow diagram for one implementation that illustratesthe stages involved in handling implementation collisions.

FIG. 9 is a process flow diagram for one implementation that illustratesthe stages involved in supporting mix-in inheritance.

FIG. 10 is a diagrammatic view of a computer system of oneimplementation.

DETAILED DESCRIPTION

The technologies and techniques herein may be described in the generalcontext as an application that allows creation and/or execution ofdynamic language script applications, but the technologies andtechniques also serve other purposes in addition to these. In oneimplementation, one or more of the techniques described herein can beimplemented as features within a dynamic programming language orframework such as MICROSOFT® ASP.NET Ajax, JavaScript, or from any othertype of program or service that allows for creation and/or execution ofapplications created in a dynamic language.

As shown in the diagram 10 of FIG. 1, in one implementation, a contractor interface 14 can be directly associated 16 with an object 18 or aninstance of an object using a dynamic language 12. The term “directlyassociated” and “direct association” as used herein means a directrelationship between the first and second entity without achieving therelationship indirectly through some other entity. In oneimplementation, by associating contracts directly with objects, typesafety can be introduced to dynamic languages. As noted in thebackground section, the term “type safety” means determining whether thecalling party meets the contract that is expected by the receiving party(the method or other member being called/accessed). One example of sucha contract that the receiving party can verify is whether or not thecalling party is passing parameters of the correct data type or not. Ininstances where type safety is violated, an exception can be thrown, oranother suitable action can be taken, such as following another path inthe program. In one implementation, a runtime environment that executesor otherwise analyzes the dynamic language script containing the directassociation is typically the one that makes the type safetydetermination, but it could also be done separately from the runtimeenvironment, such as during development of the script(s). As describedin further detail in FIGS. 5-7, contracts can also be associated withmix-ins in a similar fashion to introduce type safety to mix-ins indynamic language environments.

Turning now to FIG. 2 with continued reference to FIG. 1, a dynamiclanguage scripting application 200 operating on computing device 100 isillustrated. Dynamic language scripting application 200 is one of theapplication programs that reside on computing device 500 (of FIG. 10).However, it will be understood that dynamic language scriptingapplication 200 can alternatively or additionally be embodied ascomputer-executable instructions on one or more computers and/or indifferent variations than shown on FIG. 1. For example, some portions ofdynamic language scripting application 200 may be embodied in a softwaredevelopment environment on a developer machine, while other portions ofdynamic language scripting application 200 may be embodied in a runtimeenvironment (such as one or more web servers) that execute the softwarepreviously created on the developer machine. As another non-limitingexample of how dynamic language scripting application 200 could operatedifferently than shown in FIG. 2, multiple development computers couldbe used and/or multiple runtime computers could be used. Numerous othervariations are also possible.

Alternatively or additionally, one or more parts of dynamic languagescripting application 200 can be part of system memory 104, on othercomputers and/or applications 115, or other such variations as wouldoccur to one in the computer software art.

Dynamic language scripting application 200 includes program logic 204,which is responsible for carrying out some or all of the techniquesdescribed herein. Program logic 204 includes logic for accessing adynamic language script that directly associates contract(s) withobject(s) in a dynamic language 206 (as described below with respect toFIG. 3); logic for using the contract(s) at runtime to provide typesafety for the object(s) 208 (as described below with respect to FIG.3); logic for allowing mix-ins to be used with objects that implementfunctionality associated with assigned contract(s) and/or that meetother conditions 210 (as described below with respect to FIG. 6); logicfor associating mix-ins with the contract(s) they implement, and thecontract(s) to the target(s) when the mix-in is applied 212 (asdescribed below with respect to FIG. 5); and other logic for operatingthe dynamic language scripting application 220.

Turning now to FIGS. 3-9 with continued reference to FIGS. 1-2, thestages for implementing one or more implementations of dynamic languagescripting application 200 are described in further detail. In someimplementations, the processes of FIGS. 3-9 are at least partiallyimplemented in the operating logic of computing device 500 (of FIG. 10).FIG. 3 illustrates one implementation of the stages involved in allowinga user to directly associate contract(s) with object(s) in a dynamiclanguage. The process begins at start point 240 with receiving inputfrom a user to directly associate a contract with an object (stage 242).At design time, the user (such as a software developer), can performthis direct association between the contract and the object by insertingsource code into a dynamic language script to define the contract, andby inserting source code to map the contract to a particular object. Thecontract is used at runtime to provide type safety for the object (stage244). In other words, the dynamic language script is accessed (read orotherwise accessed), and the contract is used to determine whether ornot the calling method or member meets the requirements that areexpected by the called method or member. When type safety violations arediscovered, exceptions can be raised or other steps can be taken tohandle the situation appropriately. The stages can be repeated asdesired for other objects (stage 246). The process ends at end point248. In the discussion of FIG. 4, some code examples and furtherdiscussion of how contracts can be associated directly with objects willbe illustrated.

Turning now to FIG. 4, exemplary API's are shown for declaring and/orusing a contract with an object. An Object API 260 is shown along with aType API 272. The object API 260 contains various methods, such asGetType 262, AddInterface 264, RemoveInterface 266, GetInterfaces 268,and/or other methods 270 which are not described for the sake ofsimplicity. Let's look at each of these methods in further detail, alongwith some code examples to illustrate the concepts.

As described previously, contracts or interfaces can be directlyassociated with objects. To allow for that scenario, it is necessary tohave some API method or other way of adding a contract or interfacedeclaration to any object. In one implementation (and using the APIillustrated in FIG. 4), this can be accomplished using the AddInterfacemethod 264. Here is an example of what source code might look like usingthis method:

Object.AddInterface(instance, interfaceType);

After executing the line of code above, the object will contain a directassociation with the interface contained as a parameter above.Similarly, in one implementation (and the example shown in FIG. 4), aRemoveInterface 266 method is provided to disassociate the contract fromthe object. However, this method is not strictly necessary in otherimplementations.

The GetInterfaces method 268 is used in the exemplary API to allow forreflection. Reflection allows a program to inspect its own structure andfunctionality, which can be useful for various purposes. One common usefor reflection is for programmatically generating documentation of aprogram. Another common use of reflection is to perform duck-typing asdescribed in the background, such as to help ensure that a particularmethod uses the parameters in the way expected.

A code example of how the GetInterfaces method 268 could be used isshown below:

Object.GetInterfaces(instance)

In one implementation, use of the GetInterfaces method 268 such asillustrated above will get the interfaces that have been directlyassociated with the particular object. Alternatively or additionally,the GetInterfaces method 268 may return other associations that areindirect through the object's type.

Let's now turn to the Type API 272 shown in FIG. 4. Three methods areshown in the example, namely the IsImplementedBy method 274,IsInstanceOfType method 276, and other methods 278. In oneimplementation, existing reflection APIs that may already exist for agiven dynamic language framework can be modified to enable some of thetechniques described herein, such as to take into account not onlyclass-based interfaces but also the new instance-based ones. In such animplementation, the methods shown in the Type API 272 can be modified toaccount for this new functionality. In another implementation, newmethods can be added that separately query for reflection informationthat is now available given the ability to directly associate betweencontracts and objects.

FIG. 5 illustrates one implementation of the stages involved inassociating mix-ins with contracts. As described in the backgroundsection, a mix-in is one or more member implementations that can beadded dynamically to a target object. A mix-in can contain methods thatcan be added in one operation to an object, such as with an equivalentto an include statement that refers to the mix-in a group of code. Theprocess begins at start point 290 with receiving input from a user toadd a contract declaration for an implemented contract to a mix-in atdesign time into the dynamic language script(s) (stage 292). Animplemented contract is a contract that the mix-in implements and thatwill be dynamically added to the target. A constraint contract isoptionally associated with the mix-in implementation itself forverification of the target object before the mix-in is applied (stage294). A constraint contract is a contract that constrains what objectsthe mix-in can be applied to. At runtime, the dynamic language script isaccessed (read or otherwise accessed) in order to run the program. Theimplemented contract is associated with the target object when applyingthe mix-in to the target object (stage 296). The target object getslater used in a context that requires the implemented contract (stage297). The code in that context is distinct from the target object andthe mix-in. Because the implemented contract was added when the mix-inwas applied, the code in that context is able to verify that the targetobject satisfies the implemented contract, typically using reflection(stage 298), which is described in further detail in FIG. 6. The processends at end point 300.

Before jumping to FIG. 6, however, let's look at an example of howcontracts can be used with mix-ins. Suppose you apply anEnumerableArrayEx mix-in like this:

 var a = [″Zero″, ″One″, ″Two″, ″Three″, ″Four″, ″Five″, ″Six″];Object.mixin(a, Mixin.Collections.EnumerableArrayEx); if(Mixin.Collections.IEnumerable.isImplementedBy(a)) {   var enumerator =a.getEnumerator( );   while (enumerator.moveNext( )) {   write(enumerator.get_current( ), ″Item″);   } }

In the example above, EnumerableArrayEx is a mixin that provides animplementation of IEnumerable. The EnumerableArrayEx is being added toan array. As soon as this is done, “a” implements the interface, eventhough its type (Array) doesn't. The interface can then be used with thecertainty that checking for the contract provides. In other words, byassociating the interface with the mix-in, type safety can be provided.The mix-in packages more information here than just implementation: italso packages the set of interface types that it implements.

In the previous code example, the EnumerableArrayEx mix-in is assumingthat its target is an array. Other mix-ins may use one or severalinterfaces that they expect on their target. In one implementation, theObject.mixin method is responsible for checking that those types arepresent on the target at runtime. This is described in further detail inFIG. 7. Let's turn now to FIG. 6 before getting back to that concept.

FIG. 6 illustrates one implementation of the stages involved inrestricting the use of mix-ins based on contracts or other conditions.The process begins at start point 310 with assigning a constraintcontract and/or other condition(s) to a mix-in that must be met by atarget object (stage 312). At runtime, the constraint contract and/orcondition(s) are verified against the target object when attempting toapply the mix-in (stage 314). An example of another condition that couldbe used includes a condition evaluated based on the data contained inthe object. If the target object satisfies the constraint contractand/or other condition(s) (decision point 316), then the mix-in isapplied (stage 318). If the target object does not satisfy theconstraint contract and/or other conditions (decision point 316), thenan exception is thrown (stage 320), or another suitable action taken.While this process may seem short and simple, it is important to take amoment to emphasize exactly what just happened. By assigning aconstraint contract and/or other condition(s) to a particular mix-in,the system was able to enforce type safety for that mix-in. In otherwords, the mix-in was not allowed to be used unless the object meets therequirements required by the constraint contract or other conditions.The process ends at end point 322.

FIG. 7 illustrates one implementation of exemplary API's for registeringand/or using mix-ins with an object. In the examples shown, there is anObject API 340 and a Type API 350. The Object API 340 includes a Mixinmethod 342 and other methods 344. The Mixin method 342 was describedbriefly in the discussion of FIG. 5. The Mixin method 342 is responsiblefor checking that the specified types are present on the target objectat runtime.

While not strictly necessary, in one implementation, a helper method isprovided to declare mixins (RegisterMixin method 352), as well asadditional reflection methods that apply to mix-ins (IsMixin 354 andMixin 356). The RegisterMixin method 352 registers a mix-in, declareswhich interfaces it provides an implementation for, what types ofinstances it can extend, and a set of base mix-ins that it will inheritimplementations from. In one implementation, all parameters but the typename are optional. A code example is shown below:

Type.RegisterMixin(  typeName, implementedInterfaces, extendedTypes,mixins)

Let's now look at an example of a mix-in declaration (note that theactual implementation is not included):

Mixin.Collections.CollectionArrayEx.registerMixin( ″Mixin.Collections.CollectionArrayEx″, [Mixin.Collections.ICollection],  [Array], [Mixin.Collections.EnumerableArrayEx]);

In the example shown, the CollectionArrayEx mix-in implementsICollection (and any interface that the mix-ins it inherits fromimplement, in this case IEnumerable). The mix-in in this example appliesonly to Array instances and inherits from EnumerableArrayEx.

The IsMixin method 354 is used to determine if a type is a mix-in. Themethod returns a true or a false value to indicate whether or not thespecified type is a mix-in. Here is an example line of code for how thatmethod could be used:

Type.isMixin(type)

To extend an object or all instances of a type with a mix-in, the Mixinmethod 342 (for the Object API 340) or the Mixin method 356 (for theType API 350) can be used. Here is some example code for extending anobject using the Mixin method 342.

Object.mixin(target, mixin)

Similarly, here is some example code for extending a type (or allinstances of a type) using the Mixin method 356:

Type.mixin(target, mixin)

In one implementation, a RemoveMixin method can also be provided in theType API 350 to remove a mix-in from an object.

FIG. 8 illustrates one implementation of the stages involved in handlingimplementation collisions. The process begins at start point 370 withchecking for the existence of a method before it is being added to themix-in (stage 372). If a method does not exist (decision point 374),then an exception is thrown so a bug can be caught earlier (stage 376),such as before attempting to make a method call to a method that doesnot exist. It is better to catch this type of problem before trying toactually call the method. Some or all of the technologies and techniquesdiscussed herein now make such checks possible. The process ends at endpoint 378.

FIG. 9 illustrates one implementation of the stages involved insupporting mix-in inheritance. The process begins at start point 400with allowing a mix-in to be extended by other mix-ins (stage 402). Amix-in inherits interfaces and/or conditions packaged with any mix-inthat it is being extended with (stage 404). Let's look at these twostages in further detail to help make them clearer. As describedpreviously in the background section, one of the points of mix-ins is toenable developers to add functionality to objects as needed. There arecases where a library may want to give several different levels ofgranularity to the features and leave the choice to the developer onwhat to add. Suppose, for example, that CollectionArrayEx implementsboth ICollection and IEnumerable, but there is already an implementationof IEnumerable: EnumerableArrayEx. To avoid code duplication, it ispossible for a mix-in to be extended by other mix-ins. Essentially, thisamounts to mixing EnumerableArrayEx into CollectionArrayEx. The processends at end point 406.

As shown in FIG. 10, an exemplary computer system to use forimplementing one or more parts of the system includes a computingdevice, such as computing device 500. In its most basic configuration,computing device 500 typically includes at least one processing unit 502and memory 504. Depending on the exact configuration and type ofcomputing device, memory 504 may be volatile (such as RAM), non-volatile(such as ROM, flash memory, etc.) or some combination of the two. Thismost basic configuration is illustrated in FIG. 10 by dashed line 506.

Additionally, device 500 may also have additionalfeatures/functionality. For example, device 500 may also includeadditional storage (removable and/or non-removable) including, but notlimited to, magnetic or optical disks or tape. Such additional storageis illustrated in FIG. 10 by removable storage 508 and non-removablestorage 510. Computer storage media includes volatile and nonvolatile,removable and non-removable media implemented in any method ortechnology for storage of information such as computer readableinstructions, data structures, program modules or other data. Memory504, removable storage 508 and non-removable storage 510 are allexamples of computer storage media. Computer storage media includes, butis not limited to, RAM, ROM, EEPROM, flash memory or other memorytechnology, CD-ROM, digital versatile disks (DVD) or other opticalstorage, magnetic cassettes, magnetic tape, magnetic disk storage orother magnetic storage devices, or any other medium which can be used tostore the desired information and which can accessed by device 500. Anysuch computer storage media may be part of device 500.

Computing device 500 includes one or more communication connections 514that allow computing device 500 to communicate with othercomputers/applications 515. Device 500 may also have input device(s) 512such as keyboard, mouse, pen, voice input device, touch input device,etc. Output device(s) 511 such as a display, speakers, printer, etc. mayalso be included. These devices are well known in the art and need notbe discussed at length here. In one implementation, computing device 500includes dynamic language scripting application 200 (described in FIG. 2and other figures herein).

Although the subject matter has been described in language specific tostructural features and/or methodological acts, it is to be understoodthat the subject matter defined in the appended claims is notnecessarily limited to the specific features or acts described above.Rather, the specific features and acts described above are disclosed asexample forms of implementing the claims. All equivalents, changes, andmodifications that come within the spirit of the implementations asdescribed herein and/or by the following claims are desired to beprotected.

For example, a person of ordinary skill in the computer software artwill recognize that the examples discussed herein could be organizeddifferently on one or more computers to include fewer or additionaloptions or features than as portrayed in the examples.

What is claimed is:
 1. A system for restricting the use of mix-ins basedon meeting of a condition, comprising: a computer comprising aprocessing unit coupled to a memory, the memory storingcomputer-executable instructions which, when executed, cause theprocessing unit to perform the steps of: by calling an add interfacemethod of a target object, associating at least one condition with amix-in that must be met by the target object before the mix-in can usethe target object; enforcing type safety for the mix-in by, at runtimeof the target object, before applying the mix-in to the target object,determining whether the target object meets the at least one condition;if the target object meets the at least one condition, at runtime,applying the mix-in to the target object; and if the target object doesnot meet the at least one condition, at runtime, not allowing the mix-into be used and throwing an exception.
 2. The system of claim 1, whereinthe condition is a constraint contract that constrains objects to whichthe mix-in can be applied.
 3. The system of claim 1, wherein thecondition is evaluated based data contained in the target object.
 4. Thesystem of claim 1, wherein determining whether the target object meetsthe at least one condition is performed using reflection.
 5. The systemof claim 1, the memory storing further computer-executable instructionswhich, when executed, cause the processing unit to perform the steps of:receiving a method call to register the mix-in, the method callincluding as a parameter at least one of an interface implementationprovided by the mix-in, a set of types the mix-in is able to extend, ora set of base mix-ins from which the mix-in inherits implementations. 6.The system of claim 1, the memory storing further computer-executableinstructions which, when executed, cause the processing unit to performthe steps of: allowing the mix-in to be extended by another mix-in,wherein the another mix-in inherits an interface from the mix-in.
 7. Thesystem of claim 1, wherein the target object is an instance of a class.8. A method, comprising: by calling an add interface method of a targetobject, associating at least one condition with a mix-in that must bemet by the target object before the mix-in can use the target object;enforcing type safety for the mix-in by, at runtime of the targetobject, before applying the mix-in to the target object, determiningwhether the target object meets the at least one condition; if thetarget object meets the at least one condition, at runtime, applying themix-in to the target object; and if the target object does not meet theat least one condition, at runtime, not allowing the mix-in to be usedand throwing an exception.
 9. The method of claim 8, wherein thecondition is a constraint contract that constrains objects to which themix-in can be applied.
 10. The method of claim 8, wherein the conditionis evaluated based data contained in the target object.
 11. The methodof claim 8, wherein determining whether the target object meets the atleast one condition is performed using reflection.
 12. The method ofclaim 8, further comprising: receiving a method call to register themix-in, the method call including as a parameter at least one of aninterface implementation provided by the mix-in, a set of types themix-in is able to extend, or a set of base mix-ins from which the mix-ininherits implementations.
 13. The method of claim 8, further comprising:allowing the mix-in to be extended by another mix-in, wherein theanother mix-in inherits an interface from the mix-in.
 14. The method ofclaim 8, wherein the target object is an instance of a class.
 15. Acomputer storage memory having computer-executable instructions forcausing a computer to perform steps comprising: by calling an addinterface method of a target object, associating at least one conditionwith a mix-in that must be met by the target object before the mix-incan use the target object; enforcing type safety for the mix-in by, atruntime of the target object, before applying the mix-in to the targetobject, determining whether the target object meets the at least onecondition; if the target object meets the at least one condition, atruntime, applying the mix-in to the target object; and if the targetobject does not meet the at least one condition, at runtime, notallowing the mix-in to be used and throwing an exception.
 16. Thecomputer storage memory of claim 15, wherein the condition is aconstraint contract that constrains objects to which the mix-in can beapplied.
 17. The computer storage memory of claim 15, wherein thecondition is evaluated based data contained in the target object. 18.The computer storage memory of claim 15, wherein determining whether thetarget object meets the at least one condition is performed usingreflection.
 19. The computer storage memory of claim 15 having furthercomputer-executable instructions for causing the computer to performsteps comprising: receiving a method call to register the mix-in, themethod call including as a parameter at least one of an interfaceimplementation provided by the mix-in, a set of types the mix-in is ableto extend, or a set of base mix-ins from which the mix-in inheritsimplementations.
 20. The computer storage memory of claim 15 havingfurther computer-executable instructions for causing the computer toperform steps comprising: allowing the mix-in to be extended by anothermix-in, wherein the another mix-in inherits an interface from themix-in.